import Cookies from 'js-cookie';
let data 
if (Cookies.get('router')) {
   data = JSON.parse(Cookies.get('router'))
}else {
    data = []
}
  

data = data.map(item => {
    item.url = item.path
    return item
})
// 构建树结构的函数
function buildTree(data, pid = 0) {
    const tree = [];

    data.forEach(item => {
        if (item.pid === pid) {
            
            const children = buildTree(data, item.id); // 递归调用
            if (children.length > 0) {
                item.menus = children; // 将子节点数组赋给 menus 属性
            }
            tree.push(item); // 将当前节点加入树结构中
        }
    });

    return tree; // 返回构建好的树结构
}

let obj = JSON.parse(JSON.stringify(data))||[]

export let routerTree = buildTree(obj)
export let router_data = data ||[]
